package com.zhuojy.equity.mall.admin.service.car;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhuojy.equity.mall.admin.common.entity.po.car.TCarCheerPO;
import com.zhuojy.equity.mall.admin.common.pojo.ResultEntity;
import com.zhuojy.equity.mall.admin.dal.mapper.car.TCarCheerMapper;
import com.zhuojy.equity.mall.admin.dal.mapper.car.TCarFuelcardMapper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @author xrz
 * @version 1.0
 * @description:TODO
 * @date 2024/4/6 19:23
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class TCarCheerService extends ServiceImpl<TCarCheerMapper, TCarCheerPO> {
    @Autowired
    private TCarFuelcardMapper tCarFuelcardMapper;
    public ResultEntity addCarcheer(TCarCheerPO tCarCheerPO) {
        tCarCheerPO.setCreateTime(new Date());
        if (tCarCheerPO.getCheerPay() !=0) {
            System.out.println(tCarCheerPO.getCheerType()+"瑞雪测试"+tCarCheerPO.getCheerMoney());
            tCarFuelcardMapper.updateMoneyById2(String.valueOf(tCarCheerPO.getCheerPay()),tCarCheerPO.getCheerMoney());
        }
        this.baseMapper.insert(tCarCheerPO);
        return ResultEntity.OK("添加成功");
    }

    public ResultEntity findCarcheer(TCarCheerPO tCarCheerPO, Integer pageSize, Integer pageNum) {
        Page<TCarCheerPO> page = new Page<>(pageNum, pageSize);
        IPage<TCarCheerPO> tCarcheerPage = this.baseMapper.findCarcheerPagination(tCarCheerPO,page);
        return ResultEntity.OK(tCarcheerPage);
    }

    public ResultEntity echoCarcheer(Integer id) {
        TCarCheerPO tCarCheerPO = this.baseMapper.selectById(id);
        return ResultEntity.OK(tCarCheerPO);
    }

    public ResultEntity delCarcheer(Integer id) {
        this.baseMapper.deleteById(id);
        return ResultEntity.OK("操作成功");
    }

    public ResultEntity updatelCarcheer(TCarCheerPO tCarCheerPO) {
        this.baseMapper.updateById(tCarCheerPO);
        return ResultEntity.OK("修改成功");
    }
}
